<template>
  <div class="app-container customer-div">
    <el-menu :default-active="listQuery.tab" class="el-menu-demo" mode="horizontal" @select="handleSelect">
      <el-menu-item index="all">全部</el-menu-item>
      <el-menu-item index="unPay">未结清</el-menu-item>
      <el-menu-item index="financeNotice">需重新审核({{financeNoticeNum}})</el-menu-item>
      <el-menu-item index="batchReview">分批审核</el-menu-item>
<!--      <el-menu-item index="txContract" v-if="isCanseeTx">桐鑫合同</el-menu-item>-->
<!--      <el-menu-item index="rcContract" v-if="isCanseeRc">日程合同</el-menu-item>-->
    </el-menu>
    <div style="margin-top: 20px">
      <!--搜索-->
      <el-form :inline="true" :model="listQuery" size="mini" label-width="140px" v-if="listQuery.tab != 'financeNotice'">
        <div class="search-div">
          <el-collapse v-model="activeNames">
            <el-collapse-item title="常用搜索条件" name="1">
              <el-form-item label="客户名称：">
                <el-autocomplete
                  clearable
                  class="inline-input"
                  value-key="customerName"
                  :fetch-suggestions="querySearch"
                  v-model="listQuery.keywords"
                  placeholder="请输入内容"
                  @select="handleSelectCustomerName"
                  :trigger-on-focus="false"
                  style="width: 270px;"
                ></el-autocomplete>
              </el-form-item>
              <el-form-item label="订单编号：">
                <el-input v-model="listQuery.orderSn"></el-input>
              </el-form-item>
              <el-form-item label="合同流转状态：">
                <el-select v-model="listQuery.orderState" class="input-width" style="width:195px" placeholder="请选择" clearable multiple>
                  <el-option :value="item.orderState" :label="item.text" :key="item.orderState" v-for="item in orderStateList"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="合同上传状态：">
                <el-select v-model="listQuery.hasUploadContract" placeholder="请选择" clearable style="width:100px">
                  <el-option :key="1" label="是" :value="1"></el-option>
                  <el-option :key="0" label="否" :value="0"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="支付状态：" v-if="listQuery.tab == 'all' || listQuery.tab == 'txContract' " >
                <el-select v-model="listQuery.payState" class="input-width" style="width:150px" placeholder="请选择" clearable multiple>
                  <el-option :value="0" label="未支付" :key="0"></el-option>
                  <el-option :value="1" label="未结清" :key="1"></el-option>
                  <el-option :value="2" label="已结清" :key="2"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="财务状态：">
                <el-select v-model="listQuery.financeState"  placeholder="请选择" multiple clearable style="width:100px">
                  <el-option key="0" label="未审核" value="0"></el-option>
                  <el-option key="1" label="已审核" value="1"></el-option>
                  <el-option key="2" label="已关闭" value="2"></el-option>
                  <el-option key="3" label="部分审核" value="3"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="合同公司：" >
                <el-input v-model="listQuery.fromCompany"></el-input>
              </el-form-item>

              <el-form-item label="订单日期：">
                <el-date-picker
                  :default-time="['00:00:00', '23:59:59']"
                  v-model="listQuery.createDate"
                  type="daterange"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="财务审核时间：">
                <el-date-picker
                  :default-time="['00:00:00', '23:59:59']"
                  v-model="listQuery.financeConfirmDate"
                  type="daterange"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
            </el-collapse-item>
            <el-collapse-item title="高级搜索条件" name="2">
              <el-form-item label="业务员：">
                <el-select v-model="listQuery.userId" filterable placeholder="请选择" clearable>
                  <el-option
                    v-for="item in userOptionList"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="支付方式：">
                <el-select v-model="listQuery.transactionType" placeholder="请选择" clearable style="width:150px;">
                  <el-option key="BANK_PAY" label="银行汇款" value="BANK_PAY"></el-option>
                  <el-option key="COD_PAY" label="货到付款" value="COD_PAY"></el-option>
                  <el-option key="DEPOSIT_PAY" label="定金" value="DEPOSIT_PAY"></el-option>
                  <el-option key="XISHANG_PAY" label="锡商支付" value="XISHANG_PAY"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="是否为外贸订单：">
                <el-select v-model="listQuery.isChina" placeholder="请选择" clearable style="width:100px">
                  <el-option :key="2" label="是" :value="2"></el-option>
                  <el-option :key="1" label="否" :value="1"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="取消时间：">
                <el-date-picker
                  :default-time="['00:00:00', '23:59:59']"
                  v-model="listQuery.financeCancelDate"
                  type="daterange"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="实际支付日期：">
                <el-date-picker
                  :default-time="['00:00:00', '23:59:59']"
                  v-model="listQuery.payDate"
                  type="daterange"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="合同截止付款时间：">
                <el-date-picker
                  :default-time="['00:00:00', '23:59:59']"
                  v-model="listQuery.expectPayTime"
                  type="daterange"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
            </el-collapse-item>
          </el-collapse>
          <div style="text-align: right;padding-top:12px;">

                <el-button
                  size="small"
                  @click="handleSearchList()"
                  type="primary">
                  查询
                </el-button>
                <el-button
                  size="small"
                  :loading="btnLoading2"
                  v-if="accountingBatchDownLoad"
                  @click="handleBatchDownload(1)"
                  type="primary">
                  批量下载合同附件
                </el-button>
                <el-button
                  size="small"
                  :loading="btnLoading5"
                  v-if="accountingBatchDownLoad"
                  @click="handleBatchDownload(2)"
                  type="primary">
                  批量下载未回传合同附件
                </el-button>
                <el-button
                  size="small"
                  v-if="accountingExport"
                  @click="downloadExcel"
                  type="primary">
                  导出
                </el-button>
            </div>
        </div>

<!--        <el-form-item label="合同上传时间：">-->
<!--          <el-date-picker-->
<!--                  :default-time="['00:00:00', '23:59:59']"-->
<!--                  v-model="listQuery.contractTime"-->
<!--                  type="daterange"-->
<!--                  format="yyyy 年 MM 月 dd 日"-->
<!--                  value-format="yyyy-MM-dd HH:mm:ss"-->
<!--                  range-separator="至"-->
<!--                  start-placeholder="开始日期"-->
<!--                  end-placeholder="结束日期">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="是否回退：">-->
<!--          <el-select v-model="listQuery.isProcessBack" filterable placeholder="请选择" clearable style="width:100px">-->
<!--            <el-option :key="1" label="是" :value="1"></el-option>-->
<!--            <el-option :key="0" label="否" :value="0"></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->

<!--        <el-form-item label="付款超期：">-->
<!--          <el-select v-model="listQuery.remainPayHours" filterable placeholder="请选择" clearable>-->
<!--            <el-option key="3" label="3小时后超期" value="3"></el-option>-->
<!--            <el-option key="2" label="2小时后超期" value="2"></el-option>-->
<!--            <el-option key="1" label="1小时后超期" value="1"></el-option>-->
<!--            <el-option key="0" label="已超期" value="0"></el-option>-->
<!--            <el-option key="-1" label="未超期" value="-1"></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="订单类型：" >-->
<!--          <el-select v-model="listQuery.isMoresuOnlineOrder" class="input-width" style="width:150px" placeholder="请选择" clearable>-->
<!--            <el-option :key="0" label="销售订单" :value="0"></el-option>-->
<!--            <el-option :key="1" label="推广订单" :value="1"></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="合同公司：" >-->
<!--          <el-input v-model="listQuery.fromCompany"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="投委订单：" >-->
<!--          <el-select v-model="listQuery.isEntrust"  placeholder="请选择" clearable>-->
<!--            <el-option label="是" value="1"></el-option>-->
<!--            <el-option label="否" value="2"></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->


<!--        <el-form-item label="取消时间(财务已审核订单)：" label-width="200px">-->
<!--          <el-date-picker-->
<!--            :default-time="['00:00:00', '23:59:59']"-->
<!--            v-model="listQuery.checkedCancelDate"-->
<!--            type="daterange"-->
<!--            format="yyyy 年 MM 月 dd 日"-->
<!--            value-format="yyyy-MM-dd HH:mm:ss"-->
<!--            range-separator="至"-->
<!--            start-placeholder="开始日期"-->
<!--            end-placeholder="结束日期">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->

<!--        <el-form-item label="锡商还款状态：">-->
<!--          <el-select v-model="listQuery.repaidStatus" filterable placeholder="请选择" clearable style="width:100px">-->
<!--            <el-option :key="2" label="已还清" :value="2"></el-option>-->
<!--            <el-option :key="1" label="未还清" :value="1"></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="合同金额：">-->
<!--          <el-input-->
<!--            type="number"-->
<!--            v-model="listQuery.orderAmount[0]"-->
<!--            class="priceInput"-->
<!--            style="width: 100px; margin-right: 5px"-->
<!--          />-<el-input-->
<!--          type="number"-->
<!--          v-model="listQuery.orderAmount[1]"-->
<!--          class="priceInput"-->
<!--          ref="prodEnd"-->
<!--          style="width: 100px; margin-left: 5px"-->
<!--        />-->
<!--        </el-form-item>-->

      </el-form>
    </div>
      <!--数据列表-->
      <div style="font-size:14px;line-height: 30px;padding:10px 0 " v-if="listQuery.tab != 'financeNotice'">
        合同总数：<span style="font-weight: bold">{{statisticsCount }}</span>
        <span style="padding-left:20px;">合同金额：</span><span style="font-weight: bold">{{statisticsAmount }}</span>
        <span style="padding-left:20px;">商品数量：</span><span style="font-weight: bold">{{statisticsGoodsNum }}</span>
        <span style="padding-left:20px;">已审核数量：</span><span style="font-weight: bold">{{checkedGoodsNum }}</span>
        <span style="padding-left:20px;">已审核金额：</span><span style="font-weight: bold">{{checkedGoodsAmount }}</span>
      </div>

      <div class="table-container">
        <el-table
          v-loading="listLoading"
          :data="tableData"
          border
          style="width: 100%; margin-top: 20px">
          <el-table-column  label="订单号" width="140" align="center" prop="orderSn">
            <template slot-scope="scope">
              <el-link @click="toOrderDetail(scope.row.orderId)" type="primary" style="font-size:12px">
                {{scope.row.orderSn}}
              </el-link>
              <img src="../../assets/images/xianshang.png" v-if="scope.row.isMoresuOnlineOrder == 1"  style="vertical-align: middle;"/>
              <span v-if="scope.row.isEntrust == 1" style="display: inline-block;width:22px;line-height: 18px;background: green;color:#fff;font-size:12px;border-radius: 4px;text-align: center">投</span>
            </template>
          </el-table-column>
          <el-table-column
                  label="合同截止付款时间"
                  width="120"
                  align="center">
            <template slot-scope="scope">
              {{scope.row.expectPayTime}}
            </template>
          </el-table-column>
          <el-table-column
                  label="是否超期"
                  width="80"
                  align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.remainPayHours == 1" style="color:sandybrown">
                  1小时后超期
              </span>
              <span v-else-if="scope.row.remainPayHours == 2" style="color:sandybrown">
                  2小时后超期
              </span>
              <span v-else-if="scope.row.remainPayHours == 3" style="color:sandybrown">
                  3小时后超期
              </span>
              <span v-else-if="scope.row.remainPayHours <= 0" style="color:red">
                  是
              </span>
              <span v-else>
                  否
              </span>
            </template>
          </el-table-column>
          <el-table-column
            label="客户名称"
            width="150">
            <template slot-scope="scope">
                {{scope.row.customerName}}
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="客户标签"
            width="150">
            <template slot-scope="scope">
              <el-tooltip placement="bottom" effect="light">
                <div slot="content" style="max-width: 400px"> <crm-tag :item="item" v-for="item in scope.row.customerTag" :key="item.tagName" style="margin-bottom:4px;margin-right:4px"></crm-tag></div>
                <div style="padding:0 10px;width:100%; white-space: nowrap;  overflow: hidden; text-overflow: ellipsis;">
                  <crm-tag :item="item" v-for="item in scope.row.customerTag" :key="item.tagName" style="margin-bottom:4px;margin-right:4px"></crm-tag>
                </div>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column
            prop="financeState"
            label="财务状态"
            align="center"
            width="80">
          </el-table-column>
          <el-table-column
            prop="goodsFinanceCheckNum"
            label="已审核"
            align="center"
            width="80">
          </el-table-column>
          <el-table-column
            prop="goodsFinanceUnCheckNum"
            label="未审核"
            align="center"
            width="80">
          </el-table-column>
          <el-table-column
            prop="companyName"
            label="卖家公司"
            align="center"
            width="100">
          </el-table-column>
          <el-table-column
                  label="应收款"
                  width="80"
                  align="center">
            <template slot-scope="scope">
              <span style="color:red">
                 ￥{{scope.row.goodsAmount}}
              </span>
            </template>
          </el-table-column>
          <el-table-column
                  label="已收款"
                  width="80"
                  align="center">
            <template slot-scope="scope">
              ￥{{scope.row.paidAmount}}
            </template>
          </el-table-column>
          <el-table-column
                  label="未收款"
                  width="80"
                  align="center">
            <template slot-scope="scope">
              ￥{{scope.row.unPaidAmount}}
            </template>
          </el-table-column>
          <el-table-column
            label="退货金额"
            width="80"
            align="center">
            <template slot-scope="scope">
              ￥{{scope.row.deliverAmount}}
            </template>
          </el-table-column>
          <el-table-column
                  label="订单日期"
                  width="100"
                  align="center">
            <template slot-scope="scope">
              {{scope.row.orderTime}}
            </template>
          </el-table-column>


          <el-table-column
            width="250"
            label="交易方式">
            <template  slot-scope="scope">
              <div>{{scope.row.payType}}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="成交数量"
            width="80"
            align="center">
            <template slot-scope="scope">
                {{scope.row.goodsNum}}
            </template>
          </el-table-column>
          <el-table-column
            label="成交金额"
            width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.goodsAmount}}
            </template>
          </el-table-column>
          <el-table-column
                  label="运费"
                  width="100"
                  align="center">
            <template slot-scope="scope">
                {{scope.row.freight}}
            </template>
          </el-table-column>
          <el-table-column
            label="已发货数量"
            width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.goodsSendNum}}
            </template>
          </el-table-column>
          <el-table-column
            label="已发货金额"
            width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.goodsSendAmount}}
            </template>
          </el-table-column>

          <el-table-column
                  label="状态"
                  width="100"
                  align="center">
            <template slot-scope="scope">
              {{scope.row.payState | fiferPayState}}
            </template>
          </el-table-column>
          <el-table-column
                  label="支付日期"
                  width="130"
                  align="center">
            <template slot-scope="scope">
              {{scope.row.payTime}}
            </template>
          </el-table-column>
          <el-table-column
                  label="贷款金额"
                  width="100"
                  align="center">
            <template slot-scope="scope">
                {{scope.row.loanAmount }}
            </template>
          </el-table-column>
          <el-table-column
                  label="还款到期时间"
                  width="130"
                  align="center">
            <template slot-scope="scope">
                {{scope.row.repaymentDueDate }}
            </template>
          </el-table-column>
          <el-table-column
                  label="已还款金额"
                  width="100"
                  align="center">
            <template slot-scope="scope">
                {{scope.row.repaidAmount }}
            </template>
          </el-table-column>
          <el-table-column
                  label="未还款金额"
                  width="100"
                  align="center">
            <template slot-scope="scope">
                {{scope.row.noRepaidAmount }}
            </template>
          </el-table-column>
          <el-table-column
                  label="还款状态"
                  width="100"
                  align="center">
            <template slot-scope="scope">
                {{scope.row.repaidStatus | filterRepaid}}
            </template>
          </el-table-column>
          <el-table-column
                  label="还款完成时间"
                  width="130"
                  align="center">
            <template slot-scope="scope">
                {{scope.row.repaymentFinishDate?scope.row.repaymentFinishDate:"--"}}
            </template>
          </el-table-column>
<!--          <el-table-column-->
<!--                  label="备注"-->
<!--                  width="300">-->
<!--            <template slot-scope="scope">-->
<!--              {{scope.row.sendType}}-->
<!--            </template>-->
<!--          </el-table-column>-->
          <el-table-column
                  align="center"
                  label="合同上传状态"
                  width="120">
            <template slot-scope="scope">
              {{scope.row.hasUploadContract == 1 ? '是' : '否'}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  label="业务员"
                  width="100">
            <template slot-scope="scope">
                {{scope.row.userName}}
            </template>
          </el-table-column>
          <el-table-column
                  label="回退总次数"
                  width="100"
                  align="center">
            <template slot-scope="scope">
              {{scope.row.processBackNum}}
            </template>
          </el-table-column>
          <el-table-column
                  label="采购回退"
                  width="100"
                  align="center">
            <template slot-scope="scope">
              {{scope.row.purchaseBackNum}}
            </template>
          </el-table-column>
          <el-table-column
                  label="销售回退"
                  width="100"
                  align="center">
            <template slot-scope="scope">
              {{scope.row.saleBackNum}}
            </template>
          </el-table-column>
          <el-table-column
                  label="支付方式"
                  width="100"
                  align="center">
            <template slot-scope="scope">
              {{scope.row.transactionType | fiftransactionType}}
            </template>
          </el-table-column>
          <el-table-column
            label="财务审核时间"
            width="150"
            align="center">
            <template slot-scope="scope">
              {{scope.row.financeConfirmTime }}
            </template>
          </el-table-column>
          <el-table-column
            label="订单种类"
            width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.isChina}}
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="合同流转状态"
            width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.orderStateStr}}
            </template>
          </el-table-column>
          <el-table-column
            label="取消时间"
            width="130"
            align="center">
            <template slot-scope="scope">
              {{scope.row.financeCancelTime}}
            </template>
          </el-table-column>

          <el-table-column
            v-if="listQuery.tab != 'financeNotice'"
            fixed="right"
            width="180"
            label="操作"
            align="center">
            <template slot-scope="scope">
              <el-button
                  v-if="listQuery.tab != 'txContract' && listQuery.tab != 'rcContract'"
                  type="text"
                  size="mini"
                  @click="toReceiptList(scope.row)">查看收款单
              </el-button>
              <el-button
                      v-if="scope.row.needPayAmount > 0 && !scope.row.isNeedPayCheck == 1"
                  type="text"
                  size="mini"
                  @click="showDialog(scope.row)">增加收款
              </el-button>
              <el-button type="text" size="mini"
               @click="showRepayment(scope.row)"
               v-if="scope.row.transactionType =='XISHANG_PAY' && scope.row.noRepaidAmount>0 ">确认还款
              </el-button>
              <el-button
                      v-if="scope.row.isNeedPayCheck == 1"
                      type="text"
                      size="mini"
                      @click="showDialog2(scope.row)">待财务审核
              </el-button>
              <el-button
                      v-if="scope.row.contractUrl != ''"
                      type="text"
                      size="mini"
                      @click="toOpen(scope.row.contractUrl)">合同附件
              </el-button>
<!--              <el-button-->
<!--                      v-if="scope.row.contractUrl != '' && scope.row.contractFiles && scope.row.contractFiles.extension"-->
<!--                      type="text"-->
<!--                      size="mini"-->
<!--                      @click="handleDownload(scope.row)">下载合同附件-->
<!--              </el-button>-->
              <el-button
                      v-if="scope.row.orderState == 40"
                      type="text"
                      size="mini"
                      @click="toPrint(scope.row)">打印合同
              </el-button>
              <el-button
                v-if="scope.row.isNeedBatchPaid == 1"
                type="text"
                size="mini"
                @click="showBatchreview(scope.row)">分批审核
              </el-button>
              <el-button
                type="text"
                size="mini"
                @click="showLog(scope.row)">查看日志
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[10,15,20]"
        :total="count">
      </el-pagination>
    </div>

    <!--增加收款-->
    <el-dialog
            :close-on-click-modal="false"
            :beforeClose="handleClose"
            title="增加收款"
            :visible.sync="dialogVisible"
            width="700px">
      <el-form :model="priceForm" size="mini" label-width="140px"  ref="priceForm" :rules="rules">
          <el-form-item label="付款帐户：" style="margin-bottom: 0">
              {{priceForm.payAccount}}
          </el-form-item>
          <el-form-item label="付款单位类型：" style="margin-bottom: 0">
                {{priceForm.paymentUnitType}}
          </el-form-item>
          <el-form-item label="交易方式：" style="margin-bottom: 0">
              {{priceForm.orderRemark }}
          </el-form-item>
          <el-form-item label="合同金额：" style="margin-bottom: 0">
              {{priceForm.goodsAmount}}
          </el-form-item>
          <el-form-item label="合同商品：" style="margin-bottom: 0">
             <el-table
              :data="tableData2"
              border
              style="width: 100%;">
               <el-table-column  label="结算方式" width="100" align="center">
                 <template slot-scope="scope">
                   {{scope.row.ospPayMethod}}
                 </template>
               </el-table-column>
              <el-table-column  label="品类" width="100" align="center">
                <template slot-scope="scope">
                    {{scope.row.goodsName}}
                </template>
              </el-table-column>
              <el-table-column  label="牌号" width="100" align="center">
                <template slot-scope="scope">
                  {{scope.row.goodsSn}}
                </template>
              </el-table-column>
              <el-table-column  label="单价" width="100" align="center">
                <template slot-scope="scope">
                  {{scope.row.goodsPrice}}
                </template>
              </el-table-column>
              <el-table-column  label="数量" width="100" align="center">
                <template slot-scope="scope">
                  {{scope.row.goodsNum}}
                </template>
              </el-table-column>
              <el-table-column  label="未发数量" width="100" align="center">
                <template slot-scope="scope">
                  {{scope.row.unSendNum}}
                </template>
              </el-table-column>
              <el-table-column  label="已发数量" width="100" align="center">
                <template slot-scope="scope">
                  {{scope.row.sendNum}}
                </template>
              </el-table-column>
              <el-table-column  label="最近出库时间" width="100" align="center">
                <template slot-scope="scope">
                  {{scope.row.lastSendTime}}
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
        <el-form-item label="收款帐户：" style="margin-bottom: 0">
            {{priceForm.fromCompany}}
        </el-form-item>
        <el-form-item label="收款用途：" style="margin-bottom: 0">
            {{priceForm.receivePurpose}}
        </el-form-item>
        <el-form-item label="币种：">
           {{priceForm.currency}}
        </el-form-item>
        <el-form-item label="收款方式：">
            <el-radio-group v-model="priceForm.payType" @change="changepayType">
              <el-radio label="银行汇款">银行汇款</el-radio>
              <el-radio label="承兑">承兑</el-radio>
              <el-radio label="现金">现金</el-radio>
              <el-radio label="微信">微信</el-radio>
              <el-radio label="支付宝">支付宝</el-radio>
              <el-radio label="货到付款">货到付款</el-radio>
            </el-radio-group>
          </el-form-item>
        <div v-if="priceForm.payType != '货到付款'">
          <el-form-item label="收款银行帐号：" prop="FName" v-if="priceForm.payType != '承兑'" key="FName">
            <el-select clearable v-model="priceForm.FName" style="width:400px">
              <el-option v-for="(item,index) in brandList" :key="item.FName" :value="item.FName" :label="item.FName+'【'+item.FNumber+'】'"></el-option>
            </el-select>
          </el-form-item>
          <!--        <el-form-item label="应收票据：" v-if="priceForm.payType == '承兑'" prop="document" key="document">-->
          <!--          <el-select multiple filterable v-model="priceForm.document" style="width:100%">-->
          <!--            <el-option v-for="item in billNoList" :key="item.billNo" :value="item.billNo" :label="'收票日期：'+item.billDate+'，金额：'+item.billAmount+'，票据号：'+item.billNo+'，票据包号：'+item.billNumber"></el-option>-->
          <!--          </el-select>-->
          <!--        </el-form-item>-->
          <el-form-item label="未收款金额：">
            {{priceForm.unPaidAmount}}
          </el-form-item>
          <el-form-item label="凭证：" prop="payContent">
            <div style="width: 100%;height: 150px; border:1px solid #DCDFE6;cursor: default;border-radius: 4px;">
              <img id="imgNode" :src="priceForm.payContent" style="width:100%;height:100%;object-fit: contain;border:0" v-show="priceForm.payContent">
              <el-input type="hidden" v-model="priceForm.payContent"></el-input>
            </div>
          </el-form-item>
          <el-form-item label="确认金额：" prop="payAmount">
            <el-input-number v-model="priceForm.payAmount" :precision="2" :min="0" :disabled="priceForm.payType == '承兑'" :max="Number((priceForm.unPaidAmount-priceForm.balance).toFixed(2))" style="width:130px;display: inline-block"></el-input-number>
            <!--              <el-input v-model="priceForm.payAmount" style="width:130px;display: inline-block"></el-input>-->
            <span style="font-size:12px;color:#aaa;padding-left:10px">请确认金额与凭证一致</span>
            <!--              <el-checkbox v-model="priceForm.isDeposit" style="margin-left:30px;">设为定金</el-checkbox>-->
          </el-form-item>
          <el-form-item label="余额：" prop="balance">
            <el-input-number v-model="priceForm.balance" :precision="2" :min="0" :max="Number((priceForm.unPaidAmount-priceForm.payAmount).toFixed(2))" style="width:130px;display: inline-block"></el-input-number>
            <span style="font-size:12px;padding-left:10px;color:red">余额与确认金额之和不能超过未收款金额</span>
          </el-form-item>
          <el-form-item label="是否同步金蝶审核：" v-if="(priceForm.payAmount+priceForm.balance) < priceForm.unPaidAmount" prop="isPushKing">
            <el-radio v-model="priceForm.isPushKing" :label="1">是</el-radio>
            <el-radio v-model="priceForm.isPushKing" :label="0">否</el-radio>
          </el-form-item>
          <el-row>
            <el-col :span="10">
              <el-form-item label="客户是否逾期：" prop="yq">
                <el-radio-group v-model="priceForm.yq">
                  <el-radio :label="0">否</el-radio>
                  <el-radio :label="1">是</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="14" v-if="priceForm.yq == 1">
              <el-form-item label="逾期天数：" label-width="100px" prop="outDateNum">
                <el-input type="number" v-model="priceForm.outDateNum" style="width:100px"></el-input><span style="padding-left:5px">天</span>
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item label=" 实际收款时间："  prop="actualPayTime">
            <el-date-picker
              :picker-options="pickerOptions1"
              v-model="priceForm.actualPayTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>

          <el-form-item label="备注：">
            <el-input v-model="priceForm.remark" type="textarea" :autosize="{ minRows: 2, maxRows: 6}"></el-input>
          </el-form-item>
        </div>

      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="primary" @click="handleConfirm" :loading="btnLoading">确 定</el-button>
      </span>
    </el-dialog>

    <!--财务审核-->
    <el-dialog
            title="财务审核"
            :visible.sync="dialogVisible2"
            width="540px">
      <el-form :model="priceForm2" size="mini" label-width="90px"  ref="priceForm2">
        <el-form-item label="付款帐户：">
          {{priceForm2.customerName}}
        </el-form-item>
        <el-form-item label="收款方式：">
           {{priceForm2.payType}}
        </el-form-item>
        <el-form-item label="凭证：">
            <img :src="item" style="width:60px;height:60px;object-fit: contain;cursor: pointer;border:1px solid #eee;margin-right:5px;margin-bottom:5px" v-for="item in priceForm2.payCertificates" @click="fullImg(item)">
        </el-form-item>
        <el-form-item label="付款金额：">
          {{priceForm2.payAmount}}
        </el-form-item>
        <el-form-item label="备注：">
          {{priceForm2.remark}}
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="passOrder(2)" :loading="btnLoading4">审核不通过</el-button>
          <el-button type="primary" :loading="btnLoading3" @click="passOrder(1)">审核通过</el-button>
      </span>
    </el-dialog>

     <!--确认还款-->
     <el-dialog
      :close-on-click-modal="false"
      title="确认还款"
      :visible.sync="dialogVisibleRepayment"
      width="420px">
      <el-form :model="repaymentForm" size="mini" label-width="120px" ref="repaymentForm" :rules="rules1">
        <el-form-item label="本次还款金额：" prop="repaymentAmount">
              <el-input v-model="repaymentForm.repaymentAmount" style="width: 60%;"></el-input>
        </el-form-item>
        <el-form-item label="备注：">
              <el-input type="textarea" v-model="repaymentForm.remarks" style="width: 80%;"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose4">取 消</el-button>
          <el-button type="primary" @click="handleConfirm4" :loading="btnLoading4">确 定</el-button>
      </span>
    </el-dialog>

    <!--放大图片-->
    <el-dialog
            :visible.sync="dialogVisible4"
            width="800px">
      <img :src="fullSrc" style="width:100%;"/>
    </el-dialog>

    <!--分批审核-->
    <el-dialog
      title="分批审核"
      :visible.sync="dialogVisible5"
      width="800px">
      <el-form :model="reviewForm" size="mini" label-width="140px"  ref="reviewForm" :rules="reviewRules">
        <div style="padding-bottom: 15px">订单{{ reviewForm.orderSn }}目前应收款{{ reviewForm.orderAmount }}元，已收款{{ reviewForm.paidAmount }}元，未收款{{ reviewForm.unPaidAmount }}元，请根据收款情况进行审核</div>
        <el-table
          :data="reviewForm.ordGoodsList"
          border
          style="width: 100%;">
          <el-table-column  label="品类" min-width="100" align="center">
            <template slot-scope="scope">
                  {{scope.row.goodsName}}
            </template>
          </el-table-column>
          <el-table-column  label="牌号" min-width="100" align="center">
            <template slot-scope="scope">
              {{scope.row.goodsSn}}
            </template>
          </el-table-column>
          <el-table-column  label="订单备注" min-width="100" align="center">
            <template slot-scope="scope">
              {{scope.row.goodsRemark}}
            </template>
          </el-table-column>
          <el-table-column  label="合同数量" min-width="100" align="center">
            <template slot-scope="scope">
              {{scope.row.goodsNum}}
            </template>
          </el-table-column>
          <el-table-column  label="已审核数量" min-width="100" align="center">
            <template slot-scope="scope">
              {{scope.row.goodsFinanceCheckNum}}
            </template>
          </el-table-column>
          <el-table-column  label="未审核数量" min-width="100" align="center">
            <template slot-scope="scope">
              {{scope.row.goodsFinanceUnCheckNum}}
            </template>
          </el-table-column>
          <el-table-column  label="本次审核数量" min-width="100" align="center">
            <template slot-scope="scope">
                <el-form-item label-width="0px" style="margin-bottom: 0">
                  <el-input-number controls-position="right"
                                   style="width:100px;"
                                   :max="scope.row.goodsFinanceUnCheckNum" :min="0"
                                   v-model="scope.row.thisCheckNum"></el-input-number>
                </el-form-item>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="reviewhandleClose">取 消</el-button>
          <el-button type="primary" @click="reviewhandleConfirm" :loading="reviewbtnLoading">确 定</el-button>
      </span>
    </el-dialog>

    <!--查看日志-->
    <el-dialog
      title="日志"
      :visible.sync="dialogVisible6"
      width="500px">
      <div style="max-height:300px;overflow-y: auto; padding-top: 5px;" >
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in logs"
            :key="index">
                         <span>
                             <span style="padding-right:10px;">{{activity.created_at}}</span>
                             {{activity.user_name}}：{{activity.content}}
                             <span v-show="activity.remark && activity.remark != ''" style="color:red;padding-left:5px">备注：{{activity.remark}}</span>
                           <!--                             <span v-show="logTab == 1" style="padding-left:5px">耗时：{{activity.time_consuming}}</span>-->
                         </span>
          </el-timeline-item>
        </el-timeline>
        <div style="color:#888;padding:20px;text-align: center;font-size:12px" v-if="logs.length == 0">- 暂无数据 -</div>
      </div>

    </el-dialog>

  </div>
</template>
<script>
  import {getCustomerOption,downloadOldContract,txDownloadOldContract,rcDownloadOldContract,getOrderUsersList,getFinanceOrderList,getTxFinanceOrderList,getRcFinanceOrderList,postOrderPay,postTxOrderPay,postRcOrderPay,uploadBase64,downloadContract,txDownloadContract,rcDownloadContract,exportOrderList,userPayCertificate,checkUserPayCertificate,getQiniuToken,getTxQiniuToken,getRcQiniuToken,xsRepayment,getOrderStatList,getConfigList} from '@/api/partner'
  import {validateCommission} from '@/utils/validate';
    import {getFinanceOrderInfo} from '@/api/order';
    import {bankAccountList,receiveReceipt,ordGoodsInfo,ordGoodsCheck,orderLogs} from '@/api/company';
    import {formatDate} from '@/utils/date';
    import store from '@/store'
    import { mapGetters } from 'vuex'
    import axios from 'axios'
    import JSZip from 'jszip'
    import FileSaver from 'file-saver'
    import download from 'ly-downloader'
    import crmTag from "@/views/components/crmTag";
    const defaultListQuery={
      pageNum: 1,
      pageSize: 10,
      keywords: '',
      createDate:null,
      payDate:null,
      tab:'all',
      payState:[],
      orderSn:'',
      userId:null,
      hasUploadContract:null,
      contractTime:null,
      expectPayTime:null,
      isProcessBack:null,
      transactionType:null,
      remainPayHours:null,
      isMoresuOnlineOrder:null,
      fromCompany:null,
      isEntrust:'',
      isChina:'',
      repaidStatus:'',
      financeConfirmDate:[],
      financeCancelDate:[],
      orderAmount:['',''],
      financeState:[],
      orderState:null,
      checkedCancelDate:[],
    };
    const defaultPriceForm={
      orderId:'',
      payAccount : '',
      payType:'银行汇款',
      payAmount:'',
      payContent:'',
      remark:'',
      unPaidAmount:'',
      orderRemark:'',
      goodsAmount:'',
      kingState:'',// SAP状态(1财务已审核 2订单关闭 0财务未审核)
      yq:'',
      outDateNum:'',
      actualPayTime:'',
      receivePurpose:'',//收款用途
      paymentUnitType:'',//付款单位类型
      fromCompany:'',//收款帐户
      // document:[],
      FName:'',
      currency:'',
      isPushKing:null,
      balance:0
    };
    export default {
      name: "index",
      data(){
        const validatePayAmount = (rule, value, callback) => {
          let sum = Number((this.priceForm.payAmount+this.priceForm.balance).toFixed(2))
          if(!value && value !=0){
            callback(new Error('此项必填'))
          }else if(sum > this.priceForm.unPaidAmount){
            callback(new Error('收款金额与余额之和大于未付金额'))
          }else if(sum <= 0 && this.priceForm.payType != '货到付款'){
            callback(new Error('收款金额与余额之和需大于0'))
          }else if(sum < 0 && this.priceForm.payType == '货到付款'){
            callback(new Error('收款金额与余额之和需大于等于0'))
          }else {
            callback()
          }
        };
        const validateOutDateNum = (rule, value, callback) => {
          if (value <= 0) {
            callback(new Error('请输入大于0的数'))
          } else {
            callback()
          }
        };
          return {
              listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
              tableData: [],
              count: 0,
              listLoading: false,
              userOptionList:[],
              roles:store.getters.roles ? store.getters.roles : [],
              dialogVisible:false,
              priceForm:JSON.parse(JSON.stringify(defaultPriceForm)),
              rules:{
                payContent:[{required: true, trigger: 'change' ,message: '请上传凭证'}],
                payAmount:[{required: true, trigger: 'blur' ,validator: validatePayAmount,}],
                balance:[{required: true, trigger: 'blur' ,validator: validatePayAmount,}],
                isPushKing:[{required: true, trigger: 'change' ,message: '此项必填'}],
                yq:[{required: true, trigger: 'change' ,message: '此项必填'}],
                outDateNum:[{required: true, trigger: 'blur' ,validator: validateOutDateNum,}],
                actualPayTime:[{required: true, trigger: 'change' ,message: '此项必填'}],
                FName:[{required: true, trigger: 'change' ,message: '此项必填'}],
                document:[{required: true, trigger: 'change' ,message: '此项必填'}],
              },
              btnLoading : false,
              dialogVisibleRepayment:false,
              repaymentForm:{
                 repaymentAmount:'',
                 remarks:'',
                 orderId:''
               },
              rules1:{
                 repaymentAmount:[{required: true, message: '此项必填', trigger: 'blur'},],
              },
              upUrl:'',
              statisticsCount:0,
              statisticsAmount:0,
              statisticsGoodsNum:0,
              btnLoading2:false,
              btnLoading5:false,

              priceForm2:{},
              dialogVisible2:false,
              btnLoading3:false,
              btnLoading4:false,

              dialogVisible4:false,
              fullSrc:'',
              uploadToken:{
                token:'',
              },
              imgDomain:'',
            financeNoticeNum:0,
            orderStateList:[],
            tableData2:[],
            pickerOptions1: {
              disabledDate(time) {
                return time.getTime() >= Date.now();
              },
            },
            brandList:[],
            billNoList:[],

            dialogVisible5:false,
            reviewForm:{},
            reviewRules:{},
            reviewbtnLoading:false,

            dialogVisible6:false,
            logs:[],
            checkedGoodsNum:'',
            checkedGoodsAmount:'',
            activeNames:['1','2'],

          }
      },
      computed: {
        ...mapGetters([
          'name',
          'mobile',
          'userId'
        ]),
         // 财务桐鑫合同查看
      isCanseeTx() {
        if(this.roles.indexOf("financeSeeTx") != -1){
          return true
        }else{
          return false
        }
      },
       // 财务日程合同查看
       isCanseeRc() {
        if(this.roles.indexOf("financeSeeRc") != -1){
          return true
        }else{
          return false
        }
      },
        isCanCustomerByAll(){
          if(this.roles.indexOf("customerByAll") != -1){
            return true
          }else{
            return false
          }
        },
        accountingExport(){
          if(this.roles.indexOf("accountingExport") != -1){
            return true
          }else{
            return false
          }
        },
        accountingBatchDownLoad(){
          if(this.roles.indexOf("accountingBatchDownLoad") != -1){
            return true
          }else{
            return false
          }
        },
      },
      components:{crmTag},
      created() {
        let time = new Date();
        let day = time - time % (24 * 60 * 60 * 1000) - 8 * 60 * 60 * 1000;
        let end = new Date(day + 24 * 60 * 60 * 1000-1000);
        let start = new Date(day - 7*24 * 60 * 60 * 1000);
        let endDate = formatDate(end, 'yyyy-MM-dd hh:mm:ss');
        let startDate = formatDate(start, 'yyyy-MM-dd hh:mm:ss');
        this.listQuery.createDate = [startDate,endDate];
        if (localStorage.getItem('accountingListQuery')){
          this.listQuery = JSON.parse(localStorage.getItem('accountingListQuery'));
          localStorage.removeItem('accountingListQuery');
        }
        this.getUploadToken();
        this.getList();
        this.getUserOptionList();
        this.pasteImage();
        this.getOrderStatListData()

      },
      watch:{
        upUrl(){
          let data = {};
          let pic = this.upUrl.replace(/^.*?base64,/, '');
          data.pic = pic;
          data.token = this.uploadToken.token;
          data.imgDomain = this.imgDomain;
          uploadBase64(data).then((res)=>{
            if(res.src){
              this.priceForm.payContent = res.src;
            }else{
              this.$message.error('上传失败')
            }
          });
        },
      },
      filters: {
        formatCreateTime(time) {
          if(time){
            let date = new Date(time);
            return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
          }else{
            return '--'
          }
        },
        fiferPayState(val){
          if(val == 0){
            return '--'
          }else if(val == 1){
            return '未结清'
          }else if(val == 2){
            return '已结清'
          }
        },
        fifRepaymentDueDate(time) {
          if(time){
            let date = new Date(time);
            return formatDate(date, 'yyyy-MM-dd')
          }else{
            return '--'
          }
        },
        fiftransactionType(val){
          if(val == 'BANK_PAY'){
            return '银行汇款'
          }else if(val == 'COD_PAY'){
            return '货到付款'
          }else if(val == 'DEPOSIT_PAY'){
            return '定金'
          }else if(val == 'XISHANG_PAY'){
            return '锡商支付'
          }
          else{
            return '其它'
          }
        },
        filterIsChina(val){
          if(val== 2){
            return '外贸'
          } else if(val == 1){
            return '内销'
          }
        },
        filterRepaid(val){
          if(val == 1){
            return '未还清'
          }else if(val == 2){
            return '已还清'
          } else {
            return '未贷款'
          }
        },
      },
      methods:{
        showLog(item){
           this.dialogVisible6 = true;
          orderLogs({orderId:item.orderId}).then((res)=>{
              this.logs = res
          })
        },
        reviewhandleClose(){
          this.dialogVisible5 = false

        },
        reviewhandleConfirm(){
          this.reviewbtnLoading = true
          let data = {}
          data.orderId = this.reviewForm.orderId
          data.ordGoodsList = []
          this.reviewForm.ordGoodsList.forEach((el)=>{
            data.ordGoodsList.push({ogId:el.ogId,thisCheckNum:el.thisCheckNum})
          })
          ordGoodsCheck(data).then(()=>{
            this.reviewbtnLoading = false
            this.$message({
              type: 'success',
              message: '操作成功!'
            });
            this.reviewhandleClose()
            this.getList()
          }).catch(()=>{
            this.reviewbtnLoading = false
          })
        },
        showBatchreview(item){
          this.dialogVisible5 = true
          ordGoodsInfo({orderId:item.orderId}).then((res)=>{
            let data = res
            data.ordGoodsList.forEach((el)=>{
              el.thisCheckNum = 0
            })
            this.reviewForm = JSON.parse(JSON.stringify(data))
          })
        },
        getbillNoList(orderId){
          receiveReceipt({orderId:orderId}).then((res)=>{
              this.billNoList = res.list
          })
        },
        changepayType(){
          // this.priceForm.document = []
          if(this.priceForm.payType == '承兑'){
            this.priceForm.payAmount = 0
            this.priceForm.balance = this.priceForm.unPaidAmount
          }else{
            this.priceForm.payAmount = this.priceForm.unPaidAmount
            this.priceForm.balance = 0
          }
        },
        getBrandList(companyName){
          bankAccountList({companyName:companyName}).then((res)=>{
            this.brandList = res.list
          })
        },
        getOrderInfo(orderId){
          getFinanceOrderInfo({orderId:orderId}).then((res)=>{
            this.tableData2 = res
          })
        },
        //获取订单状态列表
        getOrderStatListData(){
          getOrderStatList().then((res)=>{
            this.orderStateList = res;
          })
        },
        toOpen(url){
          window.open(url)
        },
        //获取七牛TOKEN
        getUploadToken(){
          const listQuery = JSON.parse(JSON.stringify(this.listQuery))
          if(listQuery.tab == 'txContract'){
            return getTxQiniuToken().then((res)=>{
            this.uploadToken.token = res.token;
            this.imgDomain = res.domain
          })
          } else if (listQuery.tab == 'rcContract'){
            return getRcQiniuToken().then((res)=>{
            this.uploadToken.token = res.token;
            this.imgDomain = res.domain
          })
          } else {
            return getQiniuToken().then((res)=>{
            this.uploadToken.token = res.token
            this.imgDomain = res.domain
          })
          }
        },

        showRepayment(item){
          this.dialogVisibleRepayment = true;
          this.repaymentForm.orderId = item.orderId;
        },

        //关闭确认还款弹窗
        handleClose4(){
          this.dialogVisibleRepayment = false;
          this.btnLoading4 = false;
          this.repaymentForm.orderId = '';
          this.repaymentForm.remarks = '';
          this.repaymentForm.repaymentAmount = '';
        },

        //确认关联采购订单
        handleConfirm4(){
          this.$refs.repaymentForm.validate((valid) => {
            if (valid) {
              this.btnLoading4 = true;
              xsRepayment(this.repaymentForm).then((res)=>{
                this.$message({
                  type: 'success',
                  message: '操作成功!'
                });
                this.btnLoading4 = false;
                this.handleClose4();
                this.getList();
              }).catch(()=>{
                this.btnLoading4 = false;
              })
            }
          })

        },

        fullImg(src){
          this.dialogVisible4 = true;
          this.fullSrc = src;
        },

        //显示财务审核
        showDialog2(item){
          this.dialogVisible2 = true;
          userPayCertificate({orderId:item.orderId}).then((res)=>{
            this.priceForm2 = res
          })
        },

        //提交财务审核
        passOrder(type){
             if(type == 2){
               this.btnLoading4 = true;
             }else{
               this.btnLoading3 = true;
             }
              let pa = {};
              pa.orderId = this.priceForm2.orderId;
              pa.checkState = type;
              checkUserPayCertificate(pa).then(()=>{
                this.btnLoading3 = false;
                this.btnLoading4 = false;
                this.dialogVisible2 = false;
                this.$message({
                  type: 'success',
                  message: '操作成功!'
                });
                this.getList()
              }).catch(()=>{
                this.btnLoading3 = false;
                this.btnLoading4 = false;
              })

        },

        //下载excle
        downloadExcel(){
          let params = JSON.parse(JSON.stringify(this.listQuery));
          exportOrderList(params).then((res)=>{
            require.ensure([], () => {
              const { export_json_to_excel } = require('sheet/Export2Excel');
              const tHeader = res.title;
              const filterVal = res.columns;
              const list = res.list;
              const data = this.formatJson(filterVal, list);
              export_json_to_excel(tHeader, data, res.fileName);
            })
          })
        },

        //下载表格数据格式化
        formatJson(filterVal, jsonData) {
          return jsonData.map(v => filterVal.map(j => v[j]))
        },
        toOrderDetail(orderId){
          let routeData
          if(this.listQuery.tab == 'txContract') {
            routeData = this.$router.resolve({name:'txPurchaseDetail',query:{id:orderId,type:'see',seeType:'caiWu'}});
          }else if(this.listQuery.tab == 'rcContract'){
            routeData = this.$router.resolve({name:'rcPurchaseDetail',query:{id:orderId,type:'see',seeType:'caiWu'}});
          }else {
            routeData = this.$router.resolve({name:'purchaseDetail',query:{id:orderId,type:'see',seeType:'caiWu'}});
          }
          window.open(routeData.href);
        },
        //去打印页
        toPrint(item){
          let routeData
          if(this.listQuery.tab == 'txContract') {
            routeData = this.$router.resolve({name:'printingTx',query:{id:item.orderId,type:2,form:'caiwu'}});
          }else if(this.listQuery.tab == 'rcContract'){
            routeData = this.$router.resolve({name:'printingRc',query:{id:item.orderId,type:2,form:'caiwu'}});
          }else {
            routeData = this.$router.resolve({name:'printing',query:{id:item.orderId,type:2,form:'caiwu'}});
          }
          window.open(routeData.href);
          // this.$router.push({name:'printing',query:{id:item.orderId,type:2}})
        },
        //单独下载
        handleDownload(item){
          console.log("Asdfasd")
          let itemData = {url:item.contractUrl,extension:item.contractFiles.extension};
          let arr_name = itemData.url.split("/")
          let file_name = arr_name[arr_name.length - 1] + '.' + itemData.extension; // 获取文件名

          axios({
            method:'get',
            url:itemData.url,
            responseType: 'arraybuffer'
          }).then(data => {
            let eleLink = document.createElement('a');
            eleLink.download = file_name;
            eleLink.style.display = 'none';
            let blob = new Blob([data.data]);
            eleLink.href = URL.createObjectURL(blob);
            document.body.appendChild(eleLink);
            eleLink.click();
            document.body.removeChild(eleLink);
          }).catch(error => {
            this.$message({
              type: 'error',
              message: '下载失败'
            });
          })
        },
        //批量下载
        handleBatchDownload(type){
          let fn;
          if(this.listQuery.tab=='txContract'){
            if(type == 1){
            fn = txDownloadContract;
            this.btnLoading2 = true;
          }else if(type == 2){
            fn = txDownloadOldContract;
            this.btnLoading5 = true;
          }
          } else if(this.listQuery.tab=='rcContract') {
            if(type == 1){
            fn = rcDownloadContract;
            this.btnLoading2 = true;
          }else if(type == 2){
            fn = rcDownloadOldContract;
            this.btnLoading5 = true;
          }
          }else{
            if(type == 1){
            fn = downloadContract;
            this.btnLoading2 = true;
          }else if(type == 2){
            fn = downloadOldContract;
            this.btnLoading5 = true;
          }
          }

          fn(this.listQuery).then((res)=>{
            let   data = res;
            let zip = new JSZip();
            let cache = {};
            let promises = [];
            data.forEach(item => {
                const promise = this.getFile(item).then(data => { // 下载文件, 并存成ArrayBuffer对象
                const arr_name = item.url.split("attname=");
                let file_name;
                if(item.extension != ''){
                  file_name = arr_name[arr_name.length - 1] + '.' + item.extension; // 获取文件名
                }else{
                  file_name = arr_name[arr_name.length - 1] ;
                }
                zip.file(file_name, data.data, {binary: true}); // 逐个添加文件
                cache[file_name] = data.data
              });
              promises.push(promise)
            });
            Promise.all(promises).then(() => {
              zip.generateAsync({type: "blob"}).then(content => { // 生成二进制流
                FileSaver.saveAs(content, "打包下载.zip") // 利用file-saver保存文件
                this.btnLoading2 = false;
                this.btnLoading5 = false;
              }).catch(()=>{
                this.$message({
                  type: 'error',
                  message: '下载失败'
                });
                this.btnLoading2 = false;
                this.btnLoading5 = false;
              })
            }).catch(()=>{
              this.$message({
                type: 'error',
                message: '下载失败'
              });
              this.btnLoading2 = false;
              this.btnLoading5 = false;
            })
          })

        },
        getFile(item){
          return new Promise((resolve, reject) => {
            axios({
              method:'get',
              url:item.url,
              responseType: 'arraybuffer'
            }).then(data => {
              resolve({data:data.data,extension:item.extension})
            }).catch(error => {
              reject(error.toString())
            })
          })
        },
        //显示增加收款弹窗
        showDialog(item){
            this.getUploadToken().then(()=>{
             this.dialogVisible = true;
             this.priceForm = JSON.parse(JSON.stringify(defaultPriceForm));
             this.priceForm.payAccount = item.customerName;
             this.priceForm.payAmount = item.needPayAmount;
             this.priceForm.orderId = item.orderId;
             this.priceForm.unPaidAmount = item.needPayAmount;
             this.priceForm.goodsAmount = item.goodsAmount;
             this.priceForm.orderRemark = item.orderRemark;
             this.priceForm.isPushKing = null;
             this.priceForm.kingState = item.kingState;
             this.priceForm.yq = '';
             this.priceForm.outDateNum = '';
             this.priceForm.receivePurpose = item.receivePurpose
             this.priceForm.paymentUnitType = item.paymentUnitType
             this.priceForm.fromCompany = item.fromCompany
              this.priceForm.currency = item.currency
              // this.priceForm.document = []
              this.priceForm.FName = ''
             this.priceForm.actualPayTime = formatDate(new Date(), 'yyyy-MM-dd')
              this.priceForm.balance = 0
             this.getOrderInfo(item.orderId)
              // this.getbillNoList(item.orderId)
              this.getBrandList(item.fromCompany)
           })

        },

        //粘贴图片
        pasteImage() {
            let upUrl = ''
            document.addEventListener('paste',(event)=> {
            let isChrome = false;
            if (event.clipboardData || event.originalEvent) {
              //某些chrome版本使用的是event.originalEvent
              let clipboardData = (event.clipboardData || event.originalEvent.clipboardData);
              if(clipboardData.items){
                // for chrome
                let  items = clipboardData.items, len = items.length, blob = null;
                isChrome = true;
                for (let i = 0; i < len; i++) {
                  if (items[i].type.indexOf("image") !== -1) {
                    //getAsFile() 此方法只是living standard firefox ie11 并不支持
                    blob = items[i].getAsFile();
                  }
                }
                if(blob!==null){
                  let blobUrl=URL.createObjectURL(blob);
                  // this.priceForm.blobImg = blobUrl;
                  // document.getElementById("imgNode").src=blobUrl;
                  let reader = new FileReader();
                  // base64码显示

                   reader.onload =  (event)=> {
                       // event.target.result 即为图片的Base64编码字符串
                     // this.priceForm.payContent = event.target.result;
                     // document.getElementById("imgNode").src=base64_str;
                     this.upUrl = event.target.result;
                   };
                   reader.readAsDataURL(blob);
                  }

                }
              }
            });


        },

        //关闭增加收款弹窗
        handleClose(){
          this.dialogVisible = false;
          this.$refs.priceForm.clearValidate();
        },

        //提交增加收款
        handleConfirm(){
          this.$refs['priceForm'].validate((valid) => {
            if (valid) {
              this.btnLoading = true;
              let pa = {};
              pa.orderId = this.priceForm.orderId;
              pa.payType = this.priceForm.payType;
              pa.actualPayTime = this.priceForm.actualPayTime
              pa.payContent = this.priceForm.payContent;
              pa.payAmount = this.priceForm.payAmount;
              pa.remark = this.priceForm.remark;
              // pa.isDeposit = this.priceForm.isDeposit ? 1 : 0;
              pa.isPushKing = this.priceForm.isPushKing;
              if(this.priceForm.yq == 1){
                pa.outDateNum = this.priceForm.outDateNum
              }
              pa.FName = this.priceForm.FName
              if(pa.payType == '承兑'){
                pa.FName = ''
              }
              pa.balance = this.priceForm.balance
              if(pa.payType == '货到付款'){
                  delete pa.FName
                  delete pa.payContent
                  delete pa.isPushKing
                  delete pa.actualPayTime
                  delete pa.remark
                  pa.payAmount=0
                  pa.balance=0
                  pa.isPushKing=1
              }
              postOrderPay(pa).then(()=> {
                this.btnLoading = false;
                this.dialogVisible = false;
                this.getList();
                let msg = '';
                let sum = Number((pa.payAmount+pa.balance).toFixed(2))
                if(this.priceForm.kingState == 2){
                  msg = '金蝶状态为已关闭，不更新金蝶状态'
                }else if( sum >= this.priceForm.unPaidAmount && this.priceForm.kingState === 0){
                  msg = '同步金蝶审核状态成功'
                }else if(sum >= this.priceForm.unPaidAmount && this.priceForm.kingState === 1){
                  msg = '金蝶状态为已审核，不更新金蝶状态'
                }else if(sum < this.priceForm.unPaidAmount && pa.isPushKing === 1){
                  msg = '金蝶审核成功'
                }else if(sum < this.priceForm.unPaidAmount && pa.isPushKing === 0){
                  let state = this.priceForm.kingState == 0 ? '待审核' : this.priceForm.kingState == 1 ? '已审核' : '已关闭';
                  msg = '本次收款不同步金蝶状态，当前金蝶状态为' + state;
                }
                this.$confirm(msg, '提示', {
                  confirmButtonText: '确定',
                  showCancelButton:false,
                  type: 'warning'
                })
              }).catch(()=>{
                this.btnLoading = false;
              })

              // if(this.listQuery.tab == 'txContract'){
              //   postTxOrderPay(pa).then(()=> {
              //   this.btnLoading = false;
              //   this.dialogVisible = false;
              //   this.getList();
              //   let msg = '';
              //   if(this.priceForm.kingState == 2){
              //       msg = 'SAP状态为已关闭，不更新SAP状态'
              //   }else if( pa.payAmount >= this.priceForm.unPaidAmount && this.priceForm.kingState == 0){
              //       msg = '同步SAP审核状态成功'
              //   }else if(pa.payAmount >= this.priceForm.unPaidAmount && this.priceForm.kingState == 1){
              //       msg = 'SAP状态为已审核，不更新SAP状态'
              //   }else if(pa.payAmount < this.priceForm.unPaidAmount && pa.isPushKing == 1){
              //       msg = 'SAP审核成功'
              //   }else if(pa.payAmount < this.priceForm.unPaidAmount && pa.isPushKing == 0){
              //     let state = this.priceForm.kingState == 0 ? '待审核' : this.priceForm.kingState == 1 ? '已审核' : '已关闭';
              //     msg = '本次收款不同步SAP状态，当前SAP状态为' + state;
              //   }
              //   this.$confirm(msg, '提示', {
              //     confirmButtonText: '确定',
              //     showCancelButton:false,
              //     type: 'warning'
              //   })
              // }).catch(()=>{
              //   this.btnLoading = false;
              // })
              // }else if(this.listQuery.tab == 'rcContract'){
              //   postRcOrderPay(pa).then(()=> {
              //   this.btnLoading = false;
              //   this.dialogVisible = false;
              //   this.getList();
              //   let msg = '';
              //   if(this.priceForm.kingState == 2){
              //       msg = 'SAP状态为已关闭，不更新SAP状态'
              //   }else if( pa.payAmount >= this.priceForm.unPaidAmount && this.priceForm.kingState == 0){
              //       msg = '同步SAP审核状态成功'
              //   }else if(pa.payAmount >= this.priceForm.unPaidAmount && this.priceForm.kingState == 1){
              //       msg = 'SAP状态为已审核，不更新SAP状态'
              //   }else if(pa.payAmount < this.priceForm.unPaidAmount && pa.isPushKing == 1){
              //       msg = 'SAP审核成功'
              //   }else if(pa.payAmount < this.priceForm.unPaidAmount && pa.isPushKing == 0){
              //     let state = this.priceForm.kingState == 0 ? '待审核' : this.priceForm.kingState == 1 ? '已审核' : '已关闭';
              //     msg = '本次收款不同步SAP状态，当前SAP状态为' + state;
              //   }
              //   this.$confirm(msg, '提示', {
              //     confirmButtonText: '确定',
              //     showCancelButton:false,
              //     type: 'warning'
              //   })
              // }).catch(()=>{
              //   this.btnLoading = false;
              // })
              // }else {
              //   postOrderPay(pa).then(()=> {
              //   this.btnLoading = false;
              //   this.dialogVisible = false;
              //   this.getList();
              //   let msg = '';
              //   if(this.priceForm.kingState == 2){
              //       msg = 'SAP状态为已关闭，不更新SAP状态'
              //   }else if( pa.payAmount >= this.priceForm.unPaidAmount && this.priceForm.kingState == 0){
              //       msg = '同步SAP审核状态成功'
              //   }else if(pa.payAmount >= this.priceForm.unPaidAmount && this.priceForm.kingState == 1){
              //       msg = 'SAP状态为已审核，不更新SAP状态'
              //   }else if(pa.payAmount < this.priceForm.unPaidAmount && pa.isPushKing == 1){
              //       msg = 'SAP审核成功'
              //   }else if(pa.payAmount < this.priceForm.unPaidAmount && pa.isPushKing == 0){
              //     let state = this.priceForm.kingState == 0 ? '待审核' : this.priceForm.kingState == 1 ? '已审核' : '已关闭';
              //     msg = '本次收款不同步SAP状态，当前SAP状态为' + state;
              //   }
              //   this.$confirm(msg, '提示', {
              //     confirmButtonText: '确定',
              //     showCancelButton:false,
              //     type: 'warning'
              //   })
              // }).catch(()=>{
              //   this.btnLoading = false;
              // })
              // }

            }
          })
        },

          //获取员工下拉选项
          getUserOptionList(){
            getOrderUsersList().then((res)=>{
                  this.userOptionList = res;
              })
          },

          //选择员工名称
          handleSelectUserName(key,item){
              this.listQuery[key] = item.userId;
          },

          //客户名称输入匹配
          querySearch(queryString, cb){
              getCustomerOption({keywords:queryString}).then((res)=>{
                  cb(res);
              })
          },

          //选择客户名称
          handleSelectCustomerName(item){
              this.listQuery.keywords = item.customerName
          },

        /**
         * 切换选择状态
         */
        handleSelect(key, keyPath){
            this.listQuery = JSON.parse(JSON.stringify(defaultListQuery))
            this.listQuery.tab = key;
            if(key=='unPay'){
              this.listQuery.payState = [1]
            }else {
              this.listQuery.payState = [];
            }
            if(key != 'financeNotice'){
          let time = new Date();
          let day = time - time % (24 * 60 * 60 * 1000) - 8 * 60 * 60 * 1000;
          let end = new Date(day + 24 * 60 * 60 * 1000-1000);
          let start = new Date(day - 7*24 * 60 * 60 * 1000);
          let endDate = formatDate(end, 'yyyy-MM-dd hh:mm:ss');
          let startDate = formatDate(start, 'yyyy-MM-dd hh:mm:ss');
          this.listQuery.createDate = [startDate,endDate];
            }
            this.handleSearchList();
        },
        handleSizeChange(val){
          this.listQuery.pageNum = 1;
          this.listQuery.pageSize = val;
          this.getList();
        },
        handleCurrentChange(val){
          this.listQuery.pageNum = val;
          this.getList();
        },

        handleSearchList(){
          this.listQuery.pageNum = 1;
          this.getList();
        },

        //获取订单列表
        getList() {
          let data = {};
          data = JSON.parse(JSON.stringify(this.listQuery))
          if(this.listQuery.tab != 'txContract' && this.listQuery.tab != 'rcContract'){
            if(this.listQuery.tab != 'financeNotice'){
                  if(this.listQuery.tab == 'batchReview'){
                    data.isBatchPaid = 1
                    data.tab = 'all'
                  }
            }else{
                data.tab = this.listQuery.tab;
                data.pageNum = this.listQuery.pageNum;
                data.pageSize = this.listQuery.pageSize;
            }
            if(data.orderAmount[0] === '' && data.orderAmount[1] === ''){
              data.orderAmount = [];
            }else if(data.orderAmount[0] === '' && data.orderAmount[1] !== ''){
              this.$message({
                message: '请输入起始合同金额',
                type: 'warning'
              });
              return false
            }else if(data.orderAmount[0] !== '' && data.orderAmount[1] === ''){
              this.$message({
                message: '请输入终止合同金额',
                type: 'warning'
              });
              return false
            }else if(data.orderAmount[0] >  data.orderAmount[1]){
              this.$message({
                message: '起始合同金额大于终止合同金额',
                type: 'warning'
              });
              return false
          }
            this.listLoading = true;
          getFinanceOrderList(data).then(response => {
            this.tableData = response.list;
            this.count = response.count;
            this.statisticsAmount = response.statisticsAmount;
            this.statisticsCount = response.statisticsCount;
            this.statisticsGoodsNum = response.statisticsGoodsNum;
            this.financeNoticeNum = response.needRecheckNum
            this.checkedGoodsNum = response.checkedGoodsNum
            this.checkedGoodsAmount = response.checkedGoodsAmount
            this.listLoading = false;
          }).catch(()=>{
            this.listLoading = false;
          });
          } else if( this.listQuery.tab == 'txContract'){
            data = JSON.parse(JSON.stringify(this.listQuery))
            data.tab = 'all'
            getTxFinanceOrderList(data).then(response => {
            this.tableData = response.list;
            this.count = response.count;
            this.statisticsAmount = response.statisticsAmount;
            this.statisticsCount = response.statisticsCount;
            this.statisticsGoodsNum = response.statisticsGoodsNum;
            this.financeNoticeNum = response.needRecheckNum
            this.listLoading = false;
          }).catch(()=>{
            this.listLoading = false;
          }); }else{
            data = JSON.parse(JSON.stringify(this.listQuery))
            data.tab = 'all'
            getRcFinanceOrderList(data).then(response => {
            this.tableData = response.list;
            this.count = response.count;
            this.statisticsAmount = response.statisticsAmount;
            this.statisticsCount = response.statisticsCount;
            this.statisticsGoodsNum = response.statisticsGoodsNum;
            this.financeNoticeNum = response.needRecheckNum
            this.listLoading = false;
          }).catch(()=>{
            this.listLoading = false;
          });}
          },
        //去收款单页
        toReceiptList(item){
          localStorage.setItem('accountingListQuery', JSON.stringify(this.listQuery));
          this.$router.push({name:'receiptList',query:{orderSn:item.orderSn}})
        },

        },


    }
</script>

<style scoped lang="scss">
  .upload-div{
    text-align: center;
    position:relative;
    #upload{

      opacity: 0;
      position: absolute;
      z-index: 1;
      width:154px;
      height:40px
    }
  }
</style>
